/**
 * Copyright (c) 2019, ShangHai YTO Co., Ltd.
 * All right reserved.
 *
 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF YTO
 * CO., LTD.  THE CONTENTS OF THIS FILE MAY NOT BE DISCLOSED
 * TO THIRD PARTIES, COPIED OR DUPLICATED IN ANY FORM, IN WHOLE OR IN PART,
 * WITHOUT THE PRIOR WRITTEN PERMISSION OF YTO
 * CO., LTD.
 */
package org.sc.xl.apollo;

import com.baomidou.dynamic.datasource.toolkit.CryptoUtils;
import org.springframework.util.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @description: TODO 请在此添加描述
 * @reason: TODO ADD REASON(可选)
 * @author FXL
 *
 * @date 2023/8/10 11:27 
 * @since JDK 1.8
 */
public class DataSourcePropertyUtils {


    /**
     * 加密正则
     */
    private static final Pattern ENC_PATTERN = Pattern.compile("^ENC\\((.*)\\)$");
    private static String publicKey = CryptoUtils.DEFAULT_PUBLIC_KEY_STRING;


    public static String decrypt(String cipherText) {
        if (StringUtils.hasText(cipherText)) {
            Matcher matcher = ENC_PATTERN.matcher(cipherText);
            if (matcher.find()) {
                try {
                    return CryptoUtils.decrypt(publicKey, matcher.group(1));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return cipherText;
    }


    public static void main(String[] args) throws Exception {
//        System.err.println(decrypt("ENC(lc++yTAJTWt2gV1mCmQrgDqYetmxSc2fsdw69KtjVGnnhlIOPDKC8FZMu0FBt5ZZRG6ETrVc579d9AzQav4GaA==)"));
        //yto_master
//        System.err.println(decrypt("ENC(FWriL/yGnL4XPB77oxWYDIii6fs703g7vla8vCtZzy3iGekbqDAnzIpdmFhkcDFcR1mJEphNoG1sq11Vh7lo8Q==)"));
//        System.err.println(decrypt("ENC(N9Tdr+nlxO+EGVPFzd2s84iExgZ4ZoBDtSKk37L/iyhpatKrdfepx7UvpNqS24UJOXmHgI6CykPqyA/99lFhfQ==)"));
//
//        System.err.println(decrypt("ENC(DmkXyyvP/p9pWiKidskh7k6XN8gsrx/5vN3Y6W+HZLj1ACSjA2qB5aegbBW21rf07X0E6AAHyg3HdaCCKNUGqA==)"));
//        System.err.println(decrypt("ENC(funCiNwhRkRVYzg9jcVfqcfTqzJIkDOfyQaFQBpmquYYSKMtqZRomdFK3g6Vck19Uhk136b6O6LlPSos/Bp4+w==)"));

//        System.err.println(decrypt("ENC(DmkXyyvP/p9pWiKidskh7k6XN8gsrx/5vN3Y6W+HZLj1ACSjA2qB5aegbBW21rf07X0E6AAHyg3HdaCCKNUGqA==)"));
        //yto_ytrpt
        System.err.println("------------------------------------- yto_ytrpt sta -------------------------------------");
        System.err.println(decrypt("ENC(fpzFdAc7Om6D9qN585mWFasM9e/FvMqgbAybboJnwKOpMScooTJTbd75aNsibGXO2fLaJAU1ICpwe0d1sfkpXg==)"));
        System.err.println("------------------------------------- yto_ytrpt end -------------------------------------");

        System.err.println(decrypt("ENC(kpp1w/GdFc4sHgtDeOBYij4gjbhwZtokHgFrCT6sEA9JVMGhs/lcL2v6cl7V7aClSpKwRbHLerKb7eJoFm7j1A==)"));
        System.err.println(decrypt("ENC(JODJhlGbSqlejDChqAq6YtJy4QXG4iJSrf3p9hzdhDBIhlJDS/aEC6Or0MjBGnBqcYsGl8AxowD0T5sv7avVzg==)"));

        //yto-master
        System.err.println(decrypt("ENC(FWriL/yGnL4XPB77oxWYDIii6fs703g7vla8vCtZzy3iGekbqDAnzIpdmFhkcDFcR1mJEphNoG1sq11Vh7lo8Q==)"));
        System.err.println(decrypt("ENC(gI+fF9Vy33I6+cN2dQSzP2cfqJAjkVrt57+J8gmW7LGTl/rxdwD+mfl7+bwWR/ro/N1H+ecW7w6UM27u/4S0aQ==)"));

        //ytrpt86
        System.err.println(decrypt("ENC(DmkXyyvP/p9pWiKidskh7k6XN8gsrx/5vN3Y6W+HZLj1ACSjA2qB5aegbBW21rf07X0E6AAHyg3HdaCCKNUGqA==)"));
        System.err.println(decrypt("ENC(jfvOiKaI2PtLS0QV6r6NtbueY88aI9Qp+/4Lz+78hiayO0GKUpF3f7w5g+DSv3qdHHQ9ZMOr7nUxfX3hoHjFLg==)"));

        System.err.println(decrypt("ENC(DmkXyyvP/p9pWiKidskh7k6XN8gsrx/5vN3Y6W+HZLj1ACSjA2qB5aegbBW21rf07X0E6AAHyg3HdaCCKNUGqA==)"));

        System.err.println(decrypt("ENC(AWicyKuFdCh9soNBa4OOYy2BXm0+HSqG+d0D5E4psseoUNTAt7g/ex00xJyA54x2vkGoTYzTGRCMvCbetidJ0Q==)"));
        System.err.println(decrypt("ENC(DmkXyyvP/p9pWiKidskh7k6XN8gsrx/5vN3Y6W+HZLj1ACSjA2qB5aegbBW21rf07X0E6AAHyg3HdaCCKNUGqA==)"));
        System.err.println(decrypt("ENC(AWicyKuFdCh9soNBa4OOYy2BXm0+HSqG+d0D5E4psseoUNTAt7g/ex00xJyA54x2vkGoTYzTGRCMvCbetidJ0Q==)"));
        System.err.println(decrypt("ENC(dyw/R/NNUCP3oDOSlJCtansQd2Um9N38zy7rwpGrbMoOp2kZPj/I3MKx4cv9iLM2DUHW0C4eAEHAd5xO7FkxVw==)"));
        System.err.println(decrypt("ENC(DmkXyyvP/p9pWiKidskh7k6XN8gsrx/5vN3Y6W+HZLj1ACSjA2qB5aegbBW21rf07X0E6AAHyg3HdaCCKNUGqA==)"));
        System.err.println(decrypt("ENC(FWriL/yGnL4XPB77oxWYDIii6fs703g7vla8vCtZzy3iGekbqDAnzIpdmFhkcDFcR1mJEphNoG1sq11Vh7lo8Q==)"));
        System.err.println(decrypt("ENC(dyw/R/NNUCP3oDOSlJCtansQd2Um9N38zy7rwpGrbMoOp2kZPj/I3MKx4cv9iLM2DUHW0C4eAEHAd5xO7FkxVw==)"));



        System.err.println(decrypt("ENC(NZPbbOmeI81YS1exXMJrSNVlzNnoZK+3OlkfCS9E04ux30uKM68uLcHDuuW48DsHx1WswYvjp8Aiv/qm5KU8Lw==)"));
        System.err.println(decrypt("ENC(h8W2M9UK4vEIcEd/IzGOoydHC5uQGDET0TMs9SOyoY7FLzTUHt+eNbkhpJJISS/8Pu1yj1gtPnuXLf3QnKKvsQ==)"));
    }

}